<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
	<h:outputStylesheet library="css" name="default.css" target="head" />
	<title>Modifica Prodotti</title>
</h:head>
<h:body>

	<f:metadata>
		<f:event type="preRenderView"
			listener="#{editProductBean.preloadData}" />
		<!--  <f:event type="preRenderView" listener="#{editProductBean.populate}" /> -->
	</f:metadata>
	
	<h:form>
		<p:toolbar style="heigh:35px">
			<p:toolbarGroup align="left" style="margin-top:5px; margin-left:10px">
		Benvenuto #{userBean.name} <p:separator /> #{userBean.mail}
		
		
		<p:button value="Indietro" outcome="show_prodotti.xhtml"/>
				<p:menuButton value="Opzioni">
					<p:menuitem value="Home" url="index.xhtml" icon="ui-icon-home" />
					<p:menuitem value="Elenco Utenti" outcome="show_utenti.xhtml" icon="ui-icon-person" />
					<p:menuitem value="Visualizza Pacchetti" url="show_pacchetti.xhtml"
						icon="ui-icon-suitcase" />
					<p:menuitem value="Visualizza Prodotti" url="show_prodotti.xhtml"
						icon="ui-icon-clipboard" />
				</p:menuButton>
				<p:separator />
				<p:commandButton action="#{logBean.logout}" value="Logout"
					icon="ui-icon-power" />
			</p:toolbarGroup>
		</p:toolbar>
	</h:form>
<p:messages />
	<!-- HOTEL -->
	<h:form id="newHotel" rendered="#{param['type'] eq 'hotel' }">
		<h:panelGrid columns="2">
			<h:outputLabel>Hotel</h:outputLabel>
			<br />

			<h:outputLabel for="nome_hotel">Nome</h:outputLabel>
			<p:inputText id="nome_hotel" value="#{editProductBean.hotel.nome}"
				required="true" />
			<p:message for="nome_hotel" />
			<br />

			<h:outputLabel for="via_hotel">Via</h:outputLabel>
			<p:inputText id="via_hotel" value="#{editProductBean.hotel.via}"
				required="true" />
			<p:message for="via_hotel" />
			<br />

			<h:outputLabel for="civico">Civico</h:outputLabel>
			<p:inputText id="civico"
				value="#{editProductBean.hotel.numeroCivico}" required="true" />
			<p:message for="civico" />
			<br />

			<p:dataTable id="locHot" var="loc"
				value="#{editProductBean.getAllLocalità()}" rowKey="#{loc.ID}"
				selection="#{editProductBean.localitàF}" selectionMode="single"
				immediate="true">


				<f:facet name="header">  
            Località Hotel
        </f:facet>

				<p:column headerText="ID">  
            #{loc.ID} 
        </p:column>

				<p:column headerText="Nome">  
             #{loc.nome}  
        </p:column>

				<p:column headerText="Provincia">  
              #{loc.provincia}
        </p:column>

				<p:column headerText="Stato">  
              #{loc.stato}
        </p:column>

			</p:dataTable>



		</h:panelGrid>
		<p:commandButton value="Salva" action="#{editProductBean.save}"
			reset="newHotel" validateClient="true"/>
			<p:messages />
		<br />
		<p:button value="Indietro"
			outcome="show_prodotti.xhtml?faces-redirect=true" />
	</h:form>

	<!-- LOCALITA' -->
	<h:form id="newLoc" rendered="#{param['type'] eq 'località' }">
		<h:panelGrid columns="2">
			<h:outputLabel>Località</h:outputLabel>
			<br />

			<h:outputLabel for="nome_localita">Nome</h:outputLabel>
			<p:inputText id="nome_localita"
				value="#{editProductBean.località.nome}" required="true" />
			<p:message for="nome_localita" />
			<br />

			<h:outputLabel for="provincia">Provincia</h:outputLabel>
			<p:inputText id="provincia"
				value="#{editProductBean.località.provincia}" required="true" />
			<p:message for="provincia" />
			<br />

			<h:outputLabel for="stato">Stato</h:outputLabel>
			<p:inputText id="stato" value="#{editProductBean.località.stato}"
				required="true" />
			<p:message for="stato" />
			<br />

			<h:outputLabel for="descrizione_localita">Descrizione</h:outputLabel>
			<p:inputText id="descrizione_localita"
				value="#{editProductBean.località.descrizione}" />
			<p:message for="descrizione_localita" />
			<br />
		</h:panelGrid>
		<p:commandButton value="Salva" action="#{editProductBean.save}"
			reset="newLoc" validateClient="true"/>
		<br />
		<p:button value="Indietro"
			outcome="show_prodotti.xhtml?faces-redirect=true" />
	</h:form>

	<!-- TOUR -->
	<h:form id="newTour" rendered="#{param['type'] eq 'tour' }">
		<h:panelGrid columns="2">
			<h:outputLabel>Tour</h:outputLabel>
			<br />

			<h:outputLabel for="descrizione_tour">Descrizione</h:outputLabel>
			<p:inputTextarea rows="5" cols="30" counter="counter" maxlength="140"
				counterTemplate="{0} caratteri rimanenti." autoResize="false"
				id="descrizione_tour" value="#{editProductBean.tour.descrizione}"
				required="true" />
			<h:outputLabel />
			<h:outputText id="counter" />
			<p:message for="descrizione_tour" />
			<br />



			<p:dataTable id="locTour" var="loc"
				value="#{editProductBean.getAllLocalità()}" rowKey="#{loc.ID}"
				selection="#{editProductBean.localitàF}" selectionMode="single"
				immediate="true">


				<f:facet name="header">  
            Località Hotel
        </f:facet>

				<p:column headerText="ID">  
            #{loc.ID} 
        </p:column>

				<p:column headerText="Nome">  
             #{loc.nome}  
        </p:column>

				<p:column headerText="Provincia">  
              #{loc.provincia}
        </p:column>

				<p:column headerText="Stato">  
              #{loc.stato}
        </p:column>

			</p:dataTable>

		</h:panelGrid>
		<p:commandButton value="Salva" action="#{editProductBean.save}"
			reset="newTour" validateClient="true"/>
		<br />
		<p:button value="Indietro"
			outcome="show_prodotti.xhtml?faces-redirect=true" />
	</h:form>

	<!-- TRATTA -->
	<h:form id="newTratta" rendered="#{param['type'] eq 'tratta' }">
		<h:panelGrid columns="2">
			<h:outputLabel>Tratta</h:outputLabel>
			<br />

			<p:selectOneMenu value="#{editProductBean.tratta.compagniaID}">
				<f:selectItem itemValue="-1" itemLabel="- Seleziona -"
					itemDisabled="true" />
				<f:selectItems value="#{editProductBean.getAllCompagnie()}"
					var="comp" itemValue="#{comp.ID}" itemLabel="#{comp.nome}" />
			</p:selectOneMenu>
			<br />


			<p:dataTable id="daAerop" var="aeroporto"
				value="#{editProductBean.getAllAeroporti()}"
				rowKey="#{aeroporto.ID}" selection="#{editProductBean.daAeroporto}"
				selectionMode="single" immediate="true">


				<f:facet name="header">  
            Aeroporto di partenza 
        </f:facet>

				<p:column headerText="ID">  
            #{aeroporto.ID}  
        </p:column>

				<p:column headerText="Nome">  
              #{aeroporto.name}   
        </p:column>

				<p:column headerText="Località">  
              #{prodPresBean.getLocalità(aeroporto.IDlocalità).nome}
        </p:column>

			</p:dataTable>

			<p:dataTable id="adAerop" var="aeroporto"
				value="#{editProductBean.getAllAeroporti()}"
				rowKey="#{aeroporto.ID}" selection="#{editProductBean.adAeroporto}"
				selectionMode="single" immediate="true">


				<f:facet name="header">  
            Aeroporto di arrivo
        </f:facet>

				<p:column headerText="ID">  
            #{aeroporto.ID}  
        </p:column>

				<p:column headerText="Nome">  
              #{aeroporto.name}   
        </p:column>

				<p:column headerText="Località">  
              #{prodPresBean.getLocalità(aeroporto.IDlocalità).nome}
        </p:column>

			</p:dataTable>



		</h:panelGrid>
		<p:commandButton value="Salva" action="#{editProductBean.save}"
			reset="newTratta" validateClient="true"/>
			<p:messages />
		<br />
		<p:button value="Indietro"
			outcome="show_prodotti.xhtml?faces-redirect=true" />
	</h:form>

	<!-- AEROPORTO -->
	<h:form id="newAero" rendered="#{param['type'] eq 'aeroporto' }">
		<h:panelGrid columns="2">
			<h:outputLabel>Aeroporto</h:outputLabel>
			<br />

			<h:outputLabel for="name">Nome</h:outputLabel>
			<p:inputText id="name" value="#{editProductBean.aeroporto.name}"
				required="true" />
			<p:message for="name" />
			<br />



			<p:dataTable id="locAer" var="loc"
				value="#{editProductBean.getAllLocalità()}" rowKey="#{loc.ID}"
				selection="#{editProductBean.localitàF}" selectionMode="single"
				immediate="true">


				<f:facet name="header">  
            Località Hotel
        </f:facet>

				<p:column headerText="ID">  
            #{loc.ID} 
        </p:column>

				<p:column headerText="Nome">  
             #{loc.nome}  
        </p:column>

				<p:column headerText="Provincia">  
              #{loc.provincia}
        </p:column>

				<p:column headerText="Stato">  
              #{loc.stato}
        </p:column>

			</p:dataTable>

		</h:panelGrid>
		<p:commandButton value="Salva" action="#{editProductBean.save}"
			reset="newAero" validateClient="true"/>
			<p:messages />
		<br />
		<p:button value="Indietro"
			outcome="show_prodotti.xhtml?faces-redirect=true" />
	</h:form>

	<!-- COMPAGNIA -->
	<h:form id="newComp" rendered="#{param['type'] eq 'compagnia' }">
		<h:panelGrid columns="2">
			<h:outputLabel>Compagnia</h:outputLabel>
			<br />
			<h:outputLabel for="nome">Nome</h:outputLabel>
			<p:inputText id="nome" value="#{editProductBean.compagnia.nome}"
				required="true" />
			<p:message for="nome" />
			<br />

		</h:panelGrid>

		<p:commandButton value="Salva" action="#{editProductBean.save}"
			reset="newAComp" validateClient="true"/>
			<p:messages />
		<br />
		<p:button value="Indietro"
			outcome="show_prodotti.xhtml?faces-redirect=true" />
	</h:form>
</h:body>
</html>